import { login, hotGoods } from '@/api/user'
import { setToken, getToken } from '@/utils/storage'

export default {
  namespaced: true,
  state: {
    token: getToken(),
    success: '',
    start: '',
    end: '',
    list: ''
  },
  mutations: {
    setTokenFn (state, data) {
      state.token = data.token
      state.success = data.success
      // console.log(data.token)
      setToken(data.token)
    },
    getTime (state, time) {
      state.start = time.start
      state.end = time.end
    },
    hotlist (state, list) {
      state.list = list
    }

  },
  actions: {
    async loginAction (context, payload) {
      // console.log(payload)
      const res = await login(payload)
      // console.log(res)
      context.commit('setTokenFn', res)
    },
    async goodsList (context, payload) {
      // console.log(payload)
      const res = await hotGoods(payload)
      context.commit('hotlist', res)
    },
    async getshijian (context, payload) {
      await context.commit('getTime', payload)
    }

  }
}
